package com.limbo.showapp.base;

import java.lang.ref.WeakReference;

/**
 * Created by wangqi on 2018/9/4.
 */

public abstract class BasePresenter<V extends IBaseView,M extends BaseModel> {

    //弱引用  View的引用
    protected WeakReference<V> mReference;

    protected M mModel;


    public BasePresenter() {
        this.mModel = getModel();
    }


    protected abstract M getModel();
    /**
     * 连接上View模型，类型于Activity与Fragment的连接onTachActivity()
     *
     * @param view
     */
    protected void attachView(V view) {
        mReference = new WeakReference<V>(view);
    }

    /**
     * 断开与View模型的连接，类型于Activity与Fragment的断开ondeTachActivity()
     * 防止后面做一些无用的事情造成内存泄漏
     */
    protected void detachView() {
        if (mReference != null)
            mReference.clear();
    }

    protected V getView(){
        return mReference.get();
    }

}
